package com.isoft.airportsystem.controller;

import com.isoft.airportsystem.entity.flight.Aircraft;
import com.isoft.airportsystem.service.flight.AircraftService;
import com.isoft.airportsystem.util.PageResult;
import com.isoft.airportsystem.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/aircraft")
public class AircraftController {

    @Autowired
    private AircraftService aircraftService;

    @GetMapping("/all")
    public Result<List<Aircraft>> getAllAircrafts() {
        return Result.success(aircraftService.getAllAircrafts());
    }

    @GetMapping("/{code}")
    public Result<Aircraft> getByCode(@PathVariable String code) {
        return Result.success(aircraftService.getByCode(code));
    }

    @GetMapping("/list")
    public Result<List<Aircraft>> queryAircrafts(Aircraft aircraft) {
        return Result.success(aircraftService.queryAircrafts(aircraft));
    }

    @GetMapping("/page")
    public Result<PageResult<Aircraft>> queryAircraftPage(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            Aircraft aircraft) {
        return Result.success(aircraftService.queryAircraftPage(pageNum, pageSize, aircraft));
    }
}
